/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.cggveritas.crewintranet.jms.dao.jpacontroller;

import fr.cggveritas.crewintranet.jms.dao.Dao;
import javax.persistence.*;

/**
 *
 * @author Alassane
 */
public abstract class DaoImp implements Dao{
    
	private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("crewintranetjsfPU");
    private static EntityManager em;
    
   
    @Override
    public EntityManager getEntityManager() {
        if (null == em || !em.isOpen()) {
            em = emf.createEntityManager();
        }
        return em;
    }

    @Override
    public EntityManager getNewEntityManager() {
        if (null == em || !em.isOpen()) {
            em.close();
        }
        em = emf.createEntityManager();
        return em;
    }
    
}
